(function() {

  window.activities = {};

  activities.load = function(activities) {};

  activities.initialize = function() {};

}).call(this);

(function() {

  window.app = {};

  app.initialize = function() {
    $('.btn-group').button();
    $('.dropdown-toggle').dropdown();
    if (typeof OLD_IE !== "undefined" && OLD_IE !== null) {
      return $('.placeholder').clearField();
    }
  };

}).call(this);

(function() {

  window.grammar = {};

  grammar.load = function(grammar) {};

  grammar.initialize = function() {};

}).call(this);

(function() {
  var load_class, login_fail, login_success, try_login;

  window.login = {};

  try_login = function() {
    if ($('#username-box').val() === '' || $('#password-box').val() === '') return;
    return $.post('/users/validate', {
      u: $('#username-box').val(),
      p: sha256_digest($('#password-box').val())
    }, function(data) {
      if (data.error != null) {
        return login_fail();
      } else {
        return login_success(data);
      }
    });
  };

  login_success = function(data) {
    $('#user-display').text(data.rn);
    if (!data.uc) {
      0;
    } else if (typeof data.uc === 'array') {
      0;
    } else {
      load_class(uc);
    }
    $('#login-box').modal('hide');
    $('.navbar').fadeIn();
    return $('#dojo').fadeIn();
  };

  login_fail = function() {
    console.log("Failing");
    return $.meow({
      message: "Username or password not valid!"
    });
  };

  load_class = function(uc) {
    vocab.load(uc.v);
    grammar.load(uc.g);
    activities.load(uc.a);
    $('.lang-img').hide();
    return $("#" + data.uc.la + "-img").show();
  };

  login.initialize = function() {
    $('#login-box').modal({
      backdrop: false,
      keyboard: false
    });
    return $('#login-btn').click(try_login);
  };

}).call(this);

(function() {

  window.overview = {};

  overview.load = function(people) {};

  overview.initialize = function() {};

}).call(this);

(function() {

  window.questions = {};

  questions.load = function(questions) {};

  questions.initialize = function() {};

}).call(this);

(function() {
  var $answer_box, $answer_regex, $canvas_height, $canvas_width, $current_question, $current_question_text, $data_view, $grid, $grid_hidden, $number_questions, $percent_correct, $percent_correct_text, $question_text, $questions, $selected_row_ids, $sort_column, $sort_direction, $test_ended, $test_type, $time_display, $time_per_question, $time_remaining, $timeout_timer, $total_questions_text, $vocab, $vocab_carousel, $vocab_list, ENGLISH_TO_LANGUAGE, LANGUAGE_TO_ENGLISH, SPOKEN_TO_ENGLISH, grid_filter, init_properties, int_comparer, load_canvas, load_canvas_data, show_canvas, string_comparer, update_grid_filter;

  window.vocab = {};

  LANGUAGE_TO_ENGLISH = 0;

  ENGLISH_TO_LANGUAGE = 1;

  SPOKEN_TO_ENGLISH = 2;

  $vocab = [];

  $selected_row_ids = [];

  $vocab_list = null;

  $vocab_carousel = null;

  $data_view = null;

  $grid = null;

  $sort_direction = 1;

  $sort_column = 'co';

  $canvas_width = void 0;

  $canvas_height = void 0;

  $test_type = null;

  $questions = null;

  $time_per_question = null;

  $percent_correct = null;

  $number_questions = null;

  $current_question = null;

  $answer_regex = null;

  $timeout_timer = null;

  $time_remaining = null;

  $test_ended = false;

  $grid_hidden = false;

  $current_question_text = null;

  $total_questions_text = null;

  $percent_correct_text = null;

  $question_text = null;

  $answer_box = null;

  $time_display = null;

  init_properties = function() {
    $current_question_text = $('#vocab-qnumber');
    $total_questions_text = $('#vocab-qtotal');
    $percent_correct_text = $('#vocab-pcorrect');
    $question_text = $('#vocab-question');
    $answer_box = $('#vanswerbox');
    return $time_display = $('#vtdisplay');
  };

  load_canvas_data = function(vocab, required_length) {
    var data, data_list, element, filtered_vocab, i, item, percent, v, _i, _len, _results;
    if (required_length == null) required_length = 20;
    data = [];
    for (i = 0; i <= 10; i++) {
      percent = i * 10;
      filtered_vocab = _(vocab).filter(function(item) {
        return item.pr === percent;
      });
      data.push("" + v.co + " - " + v.tr);
      if (data.length === required_length) break;
    }
    while (data.length !== required_length) {
      v = vocab[rand(vocab.length)];
      data.push("" + v.co + " - " + v.tr);
    }
    data_list = $('#vocab-canvas-data');
    _results = [];
    for (_i = 0, _len = data.length; _i < _len; _i++) {
      item = data[_i];
      element = $('<li><a>#{data}</a></li>');
      _results.push(data_list.append(element));
    }
    return _results;
  };

  show_canvas = function() {
    var initial_speed, max_speed;
    $canvas_width = $('#vocab-canvas').offsetWidth;
    $canvas_height = $('#vocab-canvas').offsetHeight;
    max_speed = app.OLD_IE ? 0 : 0.02;
    initial_speed = app.OLD_IE ? 0 : 0.05;
    $('#vocab-canvas').width($canvas_width).height($canvas_height).attr("width", $canvas_width).attr("height", $canvas_height);
    return $('#vocab-canvas').tagcanvas({
      textFont: 'Maven Pro, sans-serif',
      textColour: '#ffffff',
      outlineMethod: 'outline',
      outlineColour: 'rgba(255,255,255,0)',
      reverse: true,
      depth: 2,
      maxSpeed: max_speed,
      initial: [init_speed, 0],
      shape: 'vcylinder',
      lock: 'x'
    }, 'vocab-canvas-data');
  };

  load_canvas = function(data) {
    var required_length;
    required_length = Math.floor($('#vocab-cloud')[0].offsetWidth / 50);
    load_canvas_data(data, required_length);
    return show_canvas();
  };

  int_comparer = function(a, b) {
    var x, y;
    x = a[$sort_column];
    y = b[$sort_column];
    if (x === y) {
      return 0;
    } else if (x > y) {
      return 1;
    } else {
      return -1;
    }
  };

  string_comparer = function(a, b) {
    var x, y;
    x = a[$sort_column].toLowerCase();
    y = b[$sort_column].toLowerCase();
    x = x.replace(/^\(.+\)\s*/, "");
    y = y.replace(/^\(.+\)\s*/, "");
    if (x === y) {
      return 0;
    } else if (x > y) {
      return 1;
    } else {
      return -1;
    }
  };

  grid_filter = function(item, args) {
    if (args.category !== "" && $.inArray(args.category, item.ca)) return false;
    if (args.string !== "" && item.co.indexOf(args.string) === -1 && item.tr.indexOf(args.string) === -1) {
      return false;
    }
    return true;
  };

  update_grid_filter = function(category) {
    if (category == null) category = "";
    $data_view.setFilterArgs({
      category: category,
      string: ""
    });
    return $data_view.refresh();
  };

  vocab.load = function(data) {
    $vocab = data;
    load_canvas(data);
    return load_grid(data);
  };

}).call(this);

(function() {

  $(function() {
    activities.initialize();
    app.initialize();
    grammar.initialize();
    login.initialize();
    overview.initialize();
    questions.initialize();
    return vocab.initialize();
  });

}).call(this);
